#include <linux/init.h>
#include <linux/module.h>
#include <linux/of.h>

/*
mynode@0x12345678{
 string = "DC22041 everyone!!";
 uint   = <0x11223344 0xaabbccdd>;
 macaddr=[00 0c 29 7b f9 be];
 mixed = "hello",<0x112233>,[aa cc 00 12];
};
*/

struct device_node* node;
static int __init mynode_init(void)
{
    int i = 0;
    //通过路径获取节点
    node = of_find_node_by_path("/mynode@0x12345678");
    if(node == NULL){
        printk("获取节点失败\n");
        return -ENODATA;
    }
    printk("key = %s,value = %s\n", node->properties->name, (char*)node->properties->value);
    printk("key = %s, value = %x, value1 = %x\n", node->properties->next->name, __be32_to_cpup(node->properties->next->value), 
            __be32_to_cpup(node->properties->next->value+4));//__be32_to_cpup:将大端转化为小端（32bit）
    for(i = 0; i < 6; i++){
        printk("key = %s,value = %#x\n", node->properties->next->next->name, 
        *(unsigned char*)(node->properties->next->next->value+i));
    }
    printk("key = %s,value = %s, value1 = %x, value2 = %x\n", node->properties->next->next->next->name, 
            (char*)node->properties->next->next->next->value, __be32_to_cpup(node->properties->next->next->next->value+6),
            *(unsigned char*)node->properties->next->next->next->value+9);
    
    return 0;
}

static void __exit mynode_exit(void)
{

}

module_init(mynode_init);
module_exit(mynode_exit);
MODULE_LICENSE("GPL");